home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / GNU_KIT / DISK8.ZIP / src / makest / default.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-08  |  8.7 KB  |  320 lines

  1. /* Data base of default implicit rules for GNU Make.
  2. Copyright (C) 1988-1991 Free Software Foundation, Inc.
  3. This file is part of GNU Make.
  4.  
  5. GNU Make is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 1, or (at your option)
  8. any later version.
  9.  
  10. GNU Make is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with GNU Make; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "make.h"
  20. #include "rule.h"
  21. #include "dep.h"
  22. #include "file.h"
  23. #include "commands.h"
  24. #include "variable.h"
  25.  
  26.  
  27. /* This is the default list of suffixes for suffix rules.
  28.    `.s' must come last, so that a `.o' file will be made from
  29.    a `.c' or `.p' or ... file rather than from a .s file.  */
  30.  
  31. #ifdef atarist
  32. static char default_suffixes[]
  33.   = ".out .a .o .c .cc .y .l .s .S .h .info .dvi .tex .texinfo .sh .elc .el";
  34. #else
  35. static char default_suffixes[]
  36.   = ".out .a .ln .o .c .cc .p .f .F .r .y .l .s .S \
  37. .mod .sym .def .h .info .dvi .tex .texinfo .cweb .web .sh .elc .el";
  38. #endif
  39.  
  40. static struct pspec default_pattern_rules[] =
  41.   {
  42.     "(%)", "%",
  43.     "$(AR) $(ARFLAGS) $@ $<",
  44.  
  45.     /* The X.out rules are only in BSD's default set because
  46.        BSD Make has no null-suffix rules, so `foo.out' and
  47.        `foo' are the same thing.  */
  48.     "%.out", "%",
  49.     "@rm -f $@ \n cp $< $@",
  50.  
  51.     0, 0, 0
  52.   };
  53.  
  54. static struct pspec default_terminal_rules[] =
  55.   {
  56.     /* RCS.  */
  57.     "%", "%,v",
  58.     "test -f $@ || $(CO) $(COFLAGS) $< $@",
  59.     "%", "RCS/%,v",
  60.     "test -f $@ || $(CO) $(COFLAGS) $< $@",
  61. #ifdef atarist
  62.     "%", "rcs/%,v",
  63.     "test -f $@ || $(CO) $(COFLAGS) $< $@",
  64. #endif
  65.  
  66.     /* SCCS.  */
  67.     "%", "s.%",
  68.     "$(GET) $(GFLAGS) $<",
  69.     "%", "SCCS/s.%",
  70.     "$(GET) $(GFLAGS) $<",
  71.  
  72.     0, 0, 0
  73.   };
  74.  
  75. static char *default_suffix_rules[] =
  76.   {
  77.     ".o",
  78.     "$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  79.     ".s",
  80.     "$(LINK.s) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  81.     ".S",
  82.     "$(LINK.S) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  83.     ".c",
  84.     "$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  85.     ".cc",
  86.     "$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  87.     ".f",
  88.     "$(LINK.f) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  89.     ".p",
  90.     "$(LINK.p) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  91.     ".F",
  92.     "$(LINK.F) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  93.     ".r",
  94.     "$(LINK.r) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  95.     ".mod",
  96.     "$(COMPILE.mod) -o $@ -e $@ $^",
  97.  
  98.     ".def.sym", 
  99.     "$(COMPILE.def) -o $@ $<",
  100.  
  101.     ".sh",
  102.     "cat $< >$@ \n chmod a+x $@",
  103.  
  104.     ".s.o",
  105. #if !defined(M_XENIX) || defined(__GNUC__)
  106.     "$(COMPILE.s) -o $@ $<",
  107. #else    /* Xenix.  */
  108.     "$(COMPILE.s) -o$@ $<",
  109. #endif    /* Not Xenix.  */
  110.     ".S.o",
  111. #if !defined(M_XENIX) || defined(__GNUC__)
  112.     "$(COMPILE.S) -o $@ $<",
  113. #else    /* Xenix.  */
  114.     "$(COMPILE.S) -o$@ $<",
  115. #endif    /* Not Xenix.  */
  116.     ".c.o",
  117.     "$(COMPILE.c) $< $(OUTPUT_OPTION)",
  118.     ".cc.o",
  119.     "$(COMPILE.cc) $< $(OUTPUT_OPTION)",
  120.     ".f.o",
  121.     "$(COMPILE.f) $< $(OUTPUT_OPTION)",
  122.     ".p.o",
  123.     "$(COMPILE.p) $< $(OUTPUT_OPTION)",
  124.     ".F.o",
  125.     "$(COMPILE.F) $< $(OUTPUT_OPTION)",
  126.     ".r.o",
  127.     "$(COMPILE.r) $< $(OUTPUT_OPTION)",
  128.     ".mod.o",
  129.     "$(COMPILE.mod) -o $@ $<",
  130.  
  131.     ".c.ln",
  132.     "$(LINT.c) -C$* $<",
  133.     ".y.ln",
  134.     "$(YACC.y) $< \n $(LINT.c) -C$* y.tab.c \n $(RM) y.tab.c",
  135.     ".l.ln",
  136.     "@$(RM) $*.c \n $(LEX.l) $< > $*.c \n\
  137. $(LINT.c) -i $*.c -o $@ \n $(RM) $*.c",
  138.  
  139.     ".y.c",
  140.     "$(YACC.y) $< \n mv -f y.tab.c $@",
  141.     ".l.c",
  142.     "@$(RM) $@ \n $(LEX.l) $< > $@",
  143.  
  144.     ".F.f",
  145.     "$(PREPROCESS.F) $< $(OUTPUT_OPTION)",
  146.     ".r.f",
  147.     "$(PREPROCESS.r) $< $(OUTPUT_OPTION)",
  148.  
  149.     /* This might actually make lex.yy.c if there's no %R%
  150.        directive in $*.l, but in that case why were you
  151.        trying to make $*.r anyway?  */
  152.     ".l.r",
  153.     "$(LEX.l) $< > $@ \n mv -f lex.yy.r $@",
  154.  
  155.     ".S.s",
  156.     "$(PREPROCESS.S) $< > $@",
  157.  
  158.     ".texinfo.info",
  159.     "$(MAKEINFO) $<",
  160.  
  161.     ".tex.dvi",
  162.     "$(TEX) $<",
  163.  
  164.     ".texinfo.dvi",
  165.     "$(TEXINDEX) $(wildcard $(foreach _s_,cp fn ky pg tp vr,$*.$(_s_)))\n\
  166.      -$(foreach _f_,$(wildcard $(foreach _s_,aux cp fn ky pg tp vr,$*.$(_s_)))\
  167. ,cp $(_f_) $(_f_)O;)\n\
  168.      -$(TEX) $< \n\
  169.      $(foreach _f_,$(wildcard $(foreach _s_,aux cp fn ky pg tp vr,\
  170. $*.$(_s_))),cmp -s $(_f_)O $(_f_) ||) \\\n\
  171. ($(TEXINDEX) $(wildcard $(foreach _s_,cp fn ky pg tp vr,$*.$(_s_))); \\\n\
  172. $(TEX) $<) \n\
  173.      -rm -f $(addsuffix O,$(wildcard $(foreach _s_,\
  174. aux cp fn ky pg tp vr,$*.$(_s_))))",
  175.  
  176.     ".cweb.c",
  177.     "$(CTANGLE) $<",
  178.  
  179.     ".web.p",
  180.     "$(TANGLE) $<",
  181.  
  182.     ".cweb.tex",
  183.     "$(CWEAVE) $<",
  184.  
  185.     ".web.tex",
  186.     "$(WEAVE) $<",
  187.  
  188.     0
  189.   };
  190.  
  191. static char *default_variables[] =
  192.   {
  193.     "AR", "ar",
  194.     "ARFLAGS", "rv",
  195.     "AS", "as",
  196.     "CC", "cc",
  197.     "C++", "g++",
  198.     "CO", "co",
  199.     "CPP", "$(CC) -E",
  200.     "FC", "f77",
  201.     /* System V uses these, so explicit rules using them should work.
  202.        However, there is no way to make implicit rules use them and FC.  */
  203.     "F77", "$(FC)",
  204.     "F77FLAGS", "$(FFLAGS)",
  205. #ifdef    USG
  206.     "GET", "get",
  207. #else
  208.     "GET", "/usr/sccs/get",
  209. #endif
  210.     "LD", "ld",
  211.     "LEX", "lex",
  212.     "LINT", "lint",
  213.     "M2C", "m2c",
  214.     "PC", "pc",
  215.     "YACC", "yacc",    /* Or "bison -y"  */
  216.     "MAKEINFO", "makeinfo",
  217.     "TEX", "tex",
  218.     "TEXINDEX", "texindex",
  219.     "WEAVE", "weave",
  220.     "CWEAVE", "cweave",
  221.     "TANGLE", "tangle",
  222.     "CTANGLE", "ctangle",
  223.  
  224.     "RM", "rm -f",
  225.  
  226.     "LINK.o", "$(CC) $(LDFLAGS) $(TARGET_ARCH)",
  227.     "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  228.     "LINK.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  229.     "COMPILE.cc", "$(C++) $(C++FLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  230.     "LINK.cc", "$(C++) $(C++FLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  231.     "YACC.y", "$(YACC) $(YFLAGS)",
  232.     "LEX.l", "$(LEX) $(LFLAGS) -t",
  233.     "COMPILE.f", "$(FC) $(FFLAGS) $(TARGET_ARCH) -c",
  234.     "LINK.f", "$(FC) $(FFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  235.     "COMPILE.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  236.     "LINK.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  237.     "COMPILE.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -c",
  238.     "LINK.r", "$(FC) $(FFLAGS) $(RFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  239.     "COMPILE.def", "$(M2C) $(M2FLAGS) $(DEFFLAGS) $(TARGET_ARCH)",
  240.     "COMPILE.mod", "$(M2C) $(M2FLAGS) $(MODFLAGS) $(TARGET_ARCH)",
  241.     "COMPILE.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  242.     "LINK.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  243.     "LINK.s", "$(CC) $(ASFLAGS) $(LDFLAGS) $(TARGET_MACH)",
  244.     "COMPILE.s", "$(AS) $(ASFLAGS) $(TARGET_MACH)",
  245.     "LINK.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_MACH)",
  246.     "COMPILE.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c",
  247. #if !defined(M_XENIX) || defined(__GNUC__)
  248.     "PREPROCESS.S", "$(CC) -E $(CPPFLAGS)",
  249. #else    /* Xenix.  */
  250.     "PREPROCESS.S", "$(CC) -EP $(CPPFLAGS)",
  251. #endif    /* Not Xenix.  */
  252.     "PREPROCESS.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -F",
  253.     "PREPROCESS.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -F",
  254.     "LINT.c", "$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
  255.  
  256. #ifndef    NO_MINUS_C_MINUS_O
  257. #if !defined(M_XENIX) || defined(__GNUC__)
  258.     "OUTPUT_OPTION", "-o $@",
  259. #else    /* Xenix.  */
  260.     "OUTPUT_OPTION", "-Fo$@",
  261. #endif    /* Not Xenix.  */
  262. #endif
  263.  
  264.     0, 0
  265.   };
  266.  
  267. /* Set up the default .SUFFIXES list.  */
  268.  
  269. void
  270. set_default_suffixes ()
  271. {
  272.   suffix_file = enter_file (".SUFFIXES");
  273.  
  274.   if (no_builtin_rules_flag)
  275.     (void) define_variable ("SUFFIXES", 8, "", o_default, 0);
  276.   else
  277.     {
  278.       char *p = default_suffixes;
  279.       suffix_file->deps = (struct dep *)
  280.     multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep)),
  281.             sizeof (struct dep));
  282.       (void) define_variable ("SUFFIXES", 8, default_suffixes, o_default, 0);
  283.     }
  284. }
  285.  
  286. /* Install the default pattern rules and enter
  287.    the default suffix rules as file rules.  */
  288.  
  289. void
  290. install_default_implicit_rules ()
  291. {
  292.   register struct pspec *p;
  293.   register char **s;
  294.   
  295.   if (no_builtin_rules_flag)
  296.     return;
  297.  
  298.   for (p = default_pattern_rules; p->target != 0; ++p)
  299.     install_pattern_rule (p, 0);
  300.  
  301.   for (p = default_terminal_rules; p->target != 0; ++p)
  302.     install_pattern_rule (p, 1);
  303.  
  304.   for (s = default_suffix_rules; *s != 0; s += 2)
  305.     {
  306.       register struct file *f = enter_file (s[0]);
  307.       /* Don't clobber cmds given in a makefile if there were any.  */
  308.       if (f->cmds == 0)
  309.     {
  310.       f->cmds = (struct commands *) xmalloc (sizeof (struct commands));
  311.       f->cmds->filename = 0;
  312.       f->cmds->commands = s[1];
  313.       f->cmds->command_lines = 0;
  314.     }
  315.     }
  316.  
  317.   for (s = default_variables; *s != 0; s += 2)
  318.     (void) define_variable (s[0], strlen (s[0]), s[1], o_default, 1);
  319. }
  320.